package br.gov.dataprev.treinamento.ejb.service.impl;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import br.gov.dataprev.treinamento.ejb.modelo.Pedido;

//@MessageDriven(mappedName="java:app/jms/PagamentoCartaoQueue", activationConfig = {
//	    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
//	    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
//	})
public class PagamentoCartaoService implements MessageListener {

    public void onMessage(Message msg) {
        
    	if(msg instanceof ObjectMessage) {
    		ObjectMessage objMsg = (ObjectMessage)msg;
    		try {
				Pedido p = (Pedido)objMsg.getObject();
				Thread.currentThread().sleep(5000);
				System.out.println("Cliente = "+p.getCliente().getEmail());
			} catch (JMSException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    	
    }

}
